using System;

namespace Sunny.UI;

public abstract class DisposableObject : IDisposableObject, IDisposable
{
	private volatile bool _disposed;

	public bool IsDisposed => _disposed;

	public void ThrowIfDisposed()
	{
		if (IsDisposed)
		{
			throw new ObjectDisposedException(GetType().FullName);
		}
	}

	protected virtual void Dispose(bool disposing)
	{
		_disposed = true;
	}

	public virtual void Dispose()
	{
		Dispose(disposing: true);
		GC.SuppressFinalize(this);
	}
}
